import request from '@/utils/request'

// 新增角色
export function createRole(data) {
  return request({
    url: '/roles/',
    method: 'post',
    data
  })
}

// 删除角色
export function deleteRole(id) {
  return request({
    url: `/roles/${id}/`,
    method: 'delete'
  })
}

// 批量删除角色
export function deleteRoles(ids) {
  return request({
    url: '/roles/',
    method: 'delete',
    data: ids
  })
}

// 修改角色
export function updateRole(data) {
  return request({
    url: '/roles/',
    method: 'put',
    data
  })
}

// 设置角色权限
export function updateRolePermissions(id, permissions) {
  return request({
    url: '/roles/',
    method: 'patch',
    data: {
      id: id,
      permissions: permissions
    }
  })
}

// 获取角色列表
export function getRoles(data) {
  return request({
    url: '/roles/',
    method: 'get',
    params: data
  })
}

// 获取角色用于选框
export function getRolesOption() {
  return request({
    url: '/roles/option/',
    method: 'get'
  })
}

// 获取角色
export function getRole(id) {
  return request({
    url: `/roles/${id}/`,
    method: 'get'
  })
}
